package a.a005;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.swa99ylum.pxf.util.MergedRegionUtils;

public class Test1 {
	
	
	public static void main(String[] args) throws IOException {

		File file = new File("src/main/java/a/a005/test1.xlsx");
		System.out.println(file.getAbsolutePath());
		
		/** ===================================================== */
		FileInputStream fis = new FileInputStream(file);
		XSSFWorkbook xwb = new XSSFWorkbook(fis);
		
		
		/**
		
		XSSFSheet sheet = xwb.getSheetAt(0);
		
		//读 "合并单元格" 中的 cell
		System.out.println("=> " + sheet.getRow(0).getCell(0));
		System.out.println("=> " + sheet.getRow(1).getCell(1));
		System.out.println("=> " + sheet.getRow(3).getCell(2));
		
		//写 "合并单元格" 中的 cell
//		sheet.getRow(3).getCell(2).setCellValue(123);
//		sheet.getRow(1).getCell(1).setCellValue(456);
//		sheet.getRow(0).getCell(0).setCellValue(789);
//		sheet.getRow(3).getSheet();
		
//		sheet.a
//		cell.getAddress().
		
//		XSSFCell cell = Test1.getTopLeftCell(sheet.getRow(202).getCell(30));
		XSSFCell cell = Test1.getTopLeftCell(sheet.getRow(207).getCell(25));
		System.out.println(cell.getRowIndex() + ", " + cell.getColumnIndex());
		
		
		*/
		
		XSSFSheet sheet = xwb.getSheetAt(1);
		
		//1、单元格 aaa：当前 单元格（可能处于一个  合并单元格 中）
		XSSFCell cell = sheet.getRow(5).getCell(1);
		
		
		//2、单元格 A: aaa 的 "左上角cell"
		XSSFCell A = MergedRegionUtils.getTopLeftCell(cell);
		int rowIndexA = A.getRowIndex();
		int cellIndexA = A.getColumnIndex();
		
		System.out.println("A ==> " + A.toString());
		
		//2、单元格 B：A 的 "上一行 cell" 所在的 "合并单元格" 的 "左上角 cell"
		XSSFCell B = MergedRegionUtils.getTopLeftCell(sheet.getRow(rowIndexA-1).getCell(cellIndexA));
		
		System.out.println("B ==> " + B.toString());
		
		System.out.println("MergedRegionUtils.equals => " + MergedRegionUtils.equals(A, B));
		
		
	}
	
	

}
